<% layout('/layouts/default.html', {title: '食品信息管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa fa-list-alt"></i> ${text('食品信息管理')}
			</div>
			<div class="box-tools pull-right">
				<!--<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>-->
				<% if(hasPermi('applet:appletFoods:edit')){ %>
					<a href="${ctx}/applet/appletFoods/form" style="float: left;" class="btn btn-default btnTool" title="${text('新增食品表')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
				<a href="/fms/userfiles/fileupload/up.xls" style="float: left;margin-left: 10px" class="btn btn-default"  ><i class="fa fa-cloud-download"></i> ${text('下载模板')}</a>

				<form id="signupListImportForm" style="float: left;margin-left: 10px" class="import-file-form" enctype="multipart/form-data">
				<input type="file" name="excelFile" id="excelFile" onchange="submitBtn()" style="display:none">
				<a href="#" onclick="selectFile();"  class="btn btn-default" ><i class="fa fa-cloud-upload"></i> ${text('上传菜品')}</a>
					</form>
				<% } %>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${appletFoods}" action="${ctx}/applet/appletFoods/listData" method="post" class="form-inline "
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('食品名称')}：</label>
					<div class="control-inline">
						<#form:input path="name" maxlength="20" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('分类')}：</label>
					<div class="control-inline width-120">
						<#form:select path="category" dictType="com_foods_category" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('适用餐次')}：</label>
					<div class="control-inline width-120">
						<#form:select path="type" dictType="com_foods_type" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" id="refreshBtn" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
	function show_img(t) {
		var t = $(t).find("img");
		//页面层
		layer.open({
			type: 1,
			skin: 'layui-layer-rim', //加上边框
			area: ['80%', '80%'], //宽高
			shadeClose: true, //开启遮罩关闭
			end: function (index, layero) {
				return false;
			},
			content: '<div style="text-align:center"><img src="' + $(t).attr('src') + '" /></div>'
		});
	}
</script>
<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
//		{header:'${text("学校id")}', name:'schoolId', index:'a.school_id', width:150, align:"left", frozen:true, formatter: function(val, obj, row, act){
//			return '<a href="${ctx}/applet/appletFoods/form?id='+row.id+'" class="btnList" data-title="${text("编辑食品表")}">'+(val||row.id)+'</a>';
//		}},
		{header:'${text("食品名称")}', name:'name', index:'a.name', width:150, align:"center"},
		{header:'${text("分类")}', name:'category', index:'a.category', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('com_foods_category')}, val, '${text("未知")}', true);
		}},
		{header:'${text("销售单价（元）")}', name:'price', index:'a.price', width:150, align:"center"},
		{header:'${text("适用餐次")}', name:'type', index:'a.type', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('com_foods_type')}, val, '${text("未知")}', true);
		}},
		{header:'${text("标签")}', name:'tag', index:'a.tag', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('com_foods_tag')}, val, '${text("未知")}', true);
		}},
		{header:'${text("成品图片")}', name:'picture', index:'a.picture', width:150, align:"center",formatter:function (val) {
			return '<div onclick="show_img(this)" ><img src="'+ val+ '" style="width:50px;height:30px"/></div>'
		}},
		{header:'${text("备注说明")}', name:'remarks', index:'a.remarks', width:150, align:"center"},
		{header:'${text("更新时间")}', name:'updateDate', index:'a.update_date', width:150, align:"center"},
		{header:'${text("操作")}', name:'actions', width:120, sortable:false, title:false, formatter: function(val, obj, row, act){
			var actions = [];
			<% if(hasPermi('applet:appletFoods:edit')){ %>
				actions.push('<a href="${ctx}/applet/appletFoods/form?id='+row.id+'" class="btnList" title="${text("编辑食品信息")}"><i class="fa fa-pencil"></i></a>&nbsp;');
				actions.push('<a href="${ctx}/applet/appletFoods/delete?id='+row.id+'" class="btnList" title="${text("删除食品信息")}" data-confirm="${text("确认要删除该食品信息吗？")}"><i class="fa fa-trash-o"></i></a>&nbsp;');
			<% } %>
			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
</script>

<script>
	function selectFile() {
		$("#excelFile").trigger("click");
	}
	function submitBtn() {
		var excelFile = new FormData();
		excelFile.append('file', $('#excelFile')[0].files[0]);
//		var options = {
//			url: '${ctx}/applet/appletFoods/upload',
//			type:'post',
//			data:myform,
//			success:function (data) {
//				console.log(data)
//			},
//		}
//		$("#excelFile").ajaxSubmit(options)
		var index;
		$.ajax({
			url: '${ctx}/applet/appletFoods/upload',
			type: "post",
			data: excelFile,
			dataType: 'json',
			contentType: false,  // 告诉jQuery不要去设置Content-Type请求头
			processData: false,
			beforeSend: function () {
				index = layer.load(5, {time: 30 * 1000})
			},
			complete: function () {
				layer.close(index)
			},
			success: function (data) {
				document.getElementById("refreshBtn").click();
				js.alert("上传成功！")
			},
			error: function (data) {
				console.log(data.responseJSON.message)
				js.alert(data.responseJSON.message)

			}
		});

	}

</script>